//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CTreeData.h>
///	@path	~/src/database/xdata/
///	@date	2007/11/29
///	@desc	Tree node entry.

#pragma once

#include "xeres.h"

#include "lib/utilities/dict.h"

#include "database/IData.h"

namespace xeres {

	/*!
		\class	CTreeData
		\brief	A tree like entry node, only owns children, does not store any data.
	*/
	class CTreeData : public IData
	{
	public:

		/// \ctor
		CTreeData( const WString& name );

		/// \dtor
		virtual ~CTreeData( void );

		DECL_IOBJECT_CLASS( CTreeData , IData );

	public:

	//@ interface

		/*!
			\brief		Get the internal data type name.
			\return		Type name.
		*/
		virtual const WString& GetVarTypeName( void ) const;

		/*!
			\brief		Get internal data type id.
			\return		Type ID.
		*/
		virtual const ClassID GetVarTypeID( void ) const;

		/*!
			\brief		Get data info.
		*/
		virtual bool GetInfo( DataInfo& datainfo );

		/*!
			\brief		Get data entry key.
		*/
		virtual const Key& GetKey( void ) const;

		/*!
			\brief		Add a child node.
		*/
		virtual bool AddChild( RefWeak<IData> child );

		/*!
			\brief		Get index of child.
		*/
		virtual bool IndexOf( RefWeak<IData> child , size_t& index );

		/*!
			\brief		Delete child entry.
		*/
		virtual bool DeleteChild( size_t index );

		/*!
			\brief		Delete child entry.
		*/
		virtual bool DeleteChild( RefWeak<IData> child );

		/*!
			\brief		Delete all children.
		*/
		virtual void DeleteChildren( void );

		/*!
			\brief		Delete all children by key.
		*/
		virtual void DeleteChildren( const Key& key );

		/*!
			\brief		Get child entry count.
		*/
		virtual size_t GetChildCount( void );

		/*!
			\brief		Get child entry by key.
		*/
		virtual RefPass<IData> GetChild( const Key& key );

		/*!
			\brief		Get child entry by index.
		*/
		virtual RefPass<IData> GetChild( size_t index );

		/*!
			\brief		Get child info by key.
		*/
		virtual bool GetChildInfo( const Key& key , DataInfo& info );

		/*!
			\brief		Get child info by index.
		*/
		virtual bool GetChildInfo( size_t index , DataInfo& info , WString& name );

		/*!
			\brief		Find child by key, based on the index to start, return index and result.
		*/
		virtual bool FindChildIndex( const Key& key , size_t& index );

		/*!
			\brief		Find child by key, and based on index.
		*/
		virtual RefPass<IData> FindChild( const Key& key , size_t& index );

		/*!
			\brief		Open an entry based on current entry by path.
		*/
//		virtual RefPass<IData> OpenData( const WString& path , bool create_non_exist = false );

		/*!
			\brief		Save data entry to storage.
		*/
		virtual bool Save( void );

		/*!
			\brief		Reload data entry from storage.
		*/
		virtual bool Reload( void );

	private:

	//@ data
		Key								m_key;
		std::vector< Ref<IData> >	m_children;
	};

} // namespace xeres
